package com.kamikaze;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class Leave_edit_do {
	String leaved_date ;
	String leaved_time_begin ;
	String leaved_time_end ;
	String leave_number ;
	String leave_note ;
	
	public Leave_edit_do() {
		super();
	}

	public String getLeaved_date() {
		return leaved_date;
	}

	public void setLeaved_date(String leaved_date) {
		this.leaved_date = leaved_date;
	}

	public String getLeaved_time_begin() {
		return leaved_time_begin;
	}

	public void setLeaved_time_begin(String leaved_time_begin) {
		this.leaved_time_begin = leaved_time_begin;
	}

	public String getLeaved_time_end() {
		return leaved_time_end;
	}

	public void setLeaved_time_end(String leaved_time_end) {
		this.leaved_time_end = leaved_time_end;
	}

	public String getLeave_number() {
		return leave_number;
	}

	public void setLeave_number(String leave_number) {
		this.leave_number = leave_number;
	}

	public String getLeave_note() {
		return leave_note;
	}

	public void setLeave_note(String leave_note) {
		this.leave_note = leave_note;
	}

	public boolean edit_do(String leaved_date ,String leaved_time_begin ,
			String leaved_time_end ,String leave_number ,String leave_note,String leaved_number ){	
		boolean success=true;
		int l_number = Integer.valueOf(leave_number);
		int ld_number = Integer.valueOf(leaved_number);
		String update = "UPDATE  `j2`.`leavedata` SET " +
				" `leaved_date` =  ?,`leaved_time_begin` =  ?,`leaved_time_end` = ?,`leave_number` =  ?,`leave_note` =  ?" +
				" WHERE  `leavedata`.`leaved_number` =?";
		try {
			Class.forName("com.mysql.jdbc.Driver");
		Connection con = DriverManager
				.getConnection("jdbc:mysql://j.snpy.org/j2?user=team2&password=kamikaze&useUnicode=true&characterEncoding=UTF-8");
		PreparedStatement pstat = con.prepareStatement(update);
		pstat.setString(1, leaved_date);
		pstat.setString(2, leaved_time_begin);
		pstat.setString(3, leaved_time_end);
		pstat.setInt(4, l_number);
		pstat.setString(5, leave_note);
		pstat.setInt(6, ld_number);
		int row = pstat.executeUpdate();
		System.out.println("更動"+row+"筆資料");
		if(row==0){success=false;}
		pstat.close();
		con.close();
		} catch (ClassNotFoundException e) {e.printStackTrace();} 
		catch (SQLException e) {e.printStackTrace();}

		return success;
		
		
		
	}

	
	
}
